﻿using System;
using System.Collections.Generic;
using System.Text;

namespace He.Web.UI
{
    public class LangHelper
    {
        static PageBase page = new PageBase();
        public static string LangXmlPath = page.LangXmlPath;
        /// <summary>
        /// 取得系统支持的语言
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> GetLangDict()
        {
            List<Model.Lang> lst = new BLL.config().LoadConfig<List<Model.Lang>>(LangXmlPath);
            Dictionary<string, string> dict = new Dictionary<string, string>();
            foreach (Model.Lang item in lst)
            {
                if (item.IsShow)
                {
                    dict.Add(item.Value, item.Name);
                }
            }
            return dict;
        }


        /// <summary>
        /// 获取语言版本
        /// </summary>
        /// <param name="_lang"></param>
        /// <returns></returns>
        public static string GetLangVer(object _lang)
        {
            string lang = _lang.ToString();
            List<Model.Lang> lst = new He.BLL.config().LoadConfig<List<Model.Lang>>(LangXmlPath);
            foreach (Model.Lang item in lst)
            {
                if (lang == item.Value)
                {
                    return item.Name;
                }
            }
            return string.Empty;
        }

        /// <summary>
        /// 获取第一个开启的语言版本标识
        /// </summary>
        /// <returns></returns>
        public static string GetFirstLang()
        {
            List<Model.Lang> lst = new He.BLL.config().LoadConfig<List<Model.Lang>>(LangXmlPath);
            foreach (Model.Lang item in lst)
            {
                if (item.IsShow)
                {
                    return item.Value;
                }
            }
            return string.Empty;
        }


        /// <summary>
        /// 判断指的语言版本是否存在或开启
        /// </summary>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static bool IsExistLang(string lang)
        {
            List<Model.Lang> lst = new He.BLL.config().LoadConfig<List<Model.Lang>>(LangXmlPath);
            foreach (Model.Lang item in lst)
            {
                if (lang == item.Value && item.IsShow)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 获取语言版本数量
        /// </summary>
        /// <returns></returns>
        public static int GetLangNum()
        {
            List<Model.Lang> lst = new He.BLL.config().LoadConfig<List<Model.Lang>>(LangXmlPath);
            int num = 0;
            foreach (Model.Lang item in lst)
            {
                if (item.IsShow)
                {
                    num++;
                }
            }
            return num;
        }

        /// <summary>
        /// 获取语言栏目对应的前台绝对路径
        /// </summary>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static string GetAbsolutePath(string lang)
        {
            string siteurl = page.SiteUrl;
            switch (lang)
            {
                case "cn":
                    return string.Format("{0}/", siteurl);
                case "mobile":
                    goto case "cn";
                default:
                    return string.Format("{0}/{1}/", siteurl, lang);
            }
        }
    }
}
